<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>虚拟DOM</title>
</head>

<body>
<div id="demo1"></div>
<div id="demo2"></div>
<div id="demo3"></div>
<!-- 引入react核心库 -->
<script type="text/javascript" src="../js/react.development.js"></script>
<!-- 引入react-dom，用于支持react操作DOM -->
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<!-- 设置props的类型 -->
<script type="text/javascript" src="../js/prop-types.js"></script>
<!-- 引入babel，用于将jsx转为js -->
<script type="text/javascript" src="../js/babel.min.js"></script>

<script type="text/babel">
    class HelloWorld extends React.Component {

        constructor(props) {
            super(props);
            this.state = {
                date: new Date()
            };
        }

        componentDidMount() {
            setInterval(() => {
                console.log("执行定时器");
                this.setState({
                    date: new Date()
                })
            },1000)
        }

        render() {
            const {date} = this.state
            return (
                <div>
                    <h2>
                        {this.props.msg}
                    </h2>
                    <p>
                        Hello, <input type="text" placeholder="Your name here"/>
                        <span>{date.toTimeString()}</span>
                    </p>
                </div>
            )
        }
    }


    ReactDOM.render(<HelloWorld msg="太难了"/>, document.getElementById('demo1'))
</script>
</body>

</html>
